package edu.hitsz.prop;

import edu.hitsz.aircraft.AbstractAircraft;
import edu.hitsz.aircraft.AbstractEnemy;
import edu.hitsz.aircraft.BossEnemy;
import edu.hitsz.application.Main;
import edu.hitsz.application.MusicThread;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 炸弹道具
 *
 * @author CsCN
 */
public class BombProp extends AbstractProp {

    private final List<BombSubscriber> subscribers;

    public BombProp(int locationX, int locationY, int speedX, int speedY) {
        super(locationX, locationY, speedX, speedY);
        subscribers = new LinkedList<>();
    }

    @Override
    public int acquireProp(AbstractAircraft hero) {
        if (Main.musicFlag) {
            new MusicThread("bomb_explosion.wav").start();
        }
        int score = 0;
        for (BombSubscriber subscriber : subscribers) {
            if (subscriber instanceof AbstractEnemy){
                score += 10;
            }
            subscriber.update();
        }
        return score;
    }

    public void addSubscribers(List<? extends BombSubscriber> subscribers) {
        for(BombSubscriber subscriber : subscribers){
            if (subscriber instanceof BossEnemy){
                continue;
            }
            this.subscribers.add(subscriber);
        }
    }
}
